// pages/rank/rank.js
const {getRankList} = require('../../service/rank')

Page({
  data: {
    ranklist: [],
    show: false
  },
  onLoad() {
    // this.getTopRanks()  
  },
  showModal() {
    console.log(121)
    this.setData({ show: true })
  },
  hideBasic() {
    this.setData({ show: false })
  },
  // 点击单个item
  selectItem({currentTarget: {dataset: {item}}}) {
    const {name, id, pic} = item
    const params = {name, id, pic}
    wx.navigateTo({
      url: `../album/album?album=${encodeURIComponent(JSON.stringify(params))}`
    })
  },
  // 获取排行榜列表
  async getTopRanks() {
    const {list} = (await getRankList()).data
    if (!list.length) return
    wx.showLoading({title: '获取排行榜中'})
    const ranklist = list.map(item => ({
      pic: item.coverImgUrl,
      name: item.name,
      id: item.id,
      songList: [
        {
          singerName: '周杰伦',
          songName: '搁浅',
          id: `${Math.random().toString(36).substring(2)}a`,
        },
        {
          singerName: '林俊杰',
          songName: '起风了',
          id: `${Math.random().toString(36).substring(2)}b`,
        },
        {
          singerName: '许嵩',
          songName: '有何不可',
          id: `${Math.random().toString(36).substring(2)}c`,
        }
      ]
    }))
    this.setData({ranklist}, () => wx.hideLoading())
  }
})